package com.meichis.yndms.repository.manager;

import android.util.ArrayMap;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.reflect.TypeToken;
import com.meichis.mcsappframework.utils.MessageTools;
import com.meichis.yndms.http.CallSubscriber;
import com.meichis.yndms.http.IWebServiceCallback;
import com.meichis.yndms.http.RetrofitUtil.RxSchedulersHelper;
import com.meichis.yndms.model.VstAnalyse;
import com.meichis.yndms.repository.ApiUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xmy
 * @title
 * @remake
 * @create 2021-04-14 22:51
 */
public class VstAnalyseManager extends BaseManager {

    private static VstAnalyseManager INSTANCE;

    public static VstAnalyseManager getInstance() {
        if (INSTANCE == null) {
            synchronized (VstAnalyseManager.class) {
                if (INSTANCE == null) {
                    INSTANCE = new VstAnalyseManager();
                }
            }
        }
        return INSTANCE;
    }

    public void GetYWBFFX(final MutableLiveData<Boolean> showDialog, String IBMDealerID, int DateType, MutableLiveData<List<VstAnalyse>> data) {
        showDialog.setValue(true);
        ArrayMap<String, Object> hs = new ArrayMap<>();
        //MDS经销商ID
        hs.put("IBMDealerID", IBMDealerID);
        //时间维度：0今日 1昨日 2本周 3本月
        hs.put("DateType", DateType);
        getRootApi().GetYWBFFX(getToken(), ApiUtil.getRequestPack(hs))
                .compose(RxSchedulersHelper.rxSchedulerHelper())
                .subscribe(new CallSubscriber(new TypeToken<List<VstAnalyse>>() {
                }.getType(), new IWebServiceCallback<List<VstAnalyse>>() {
                    @Override
                    public void onSucceed(int sequence,List<VstAnalyse> resultPack, String ReturnInfo, int Return) {
                        if (resultPack == null) {
                            MessageTools.showLongToast("暂无数据！");
                            data.setValue(new ArrayList<>());
                        } else {
                            data.setValue(resultPack);
                        }
                        showDialog.setValue(false);
                    }

                    @Override
                    public void onFailure(int sequence,int errorCode, String error) {
                        showDialog.setValue(false);
                        MessageTools.showLongToast(error);
                    }
                }));

    }

}
